package com.mika.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mika.mapper.MikaMapper;
import com.mika.pojo.Mika;
import com.mika.pojo.dto.MikaPageDto;
import com.mika.pojo.vo.MikaPageVo;
import com.mika.service.MikaService;
import com.mika.web.Result;
import lombok.extern.slf4j.Slf4j;

import org.springframework.stereotype.Service;

import java.util.List;

/**
 * mika的业务层接口实现类
 *
 * @Author XiaoJiangShi
 * @Date 2022/8/22 10:11
 * @Blog blog.XiaoJiangShi.net/996.mba
 * @Description: mika的业务层接口实现类
 */
@Slf4j
@Service
public class MikaServiceImpl extends ServiceImpl<MikaMapper, Mika> implements MikaService {

    /**
     * 分页功能实现，并根据条件来进行分页
     * @param mikaPageDto 分页数据
     * @return 结果集
     */
    @Override
    public Result<MikaPageVo<Mika>> pageByCondition(MikaPageDto mikaPageDto) {
        Page<Mika> voPage = new Page<Mika>(mikaPageDto.getPage(), mikaPageDto.getPageSize());

        LambdaQueryWrapper<Mika> qu = new LambdaQueryWrapper<Mika>();
        qu.eq(StringUtils.isNotBlank(mikaPageDto.getName()), Mika::getName, mikaPageDto.getName());

        this.page(voPage, qu);

        List<Mika> records = voPage.getRecords();
        MikaPageVo<Mika> mikaPageVo = new MikaPageVo<Mika>();
        mikaPageVo.setList(records);
        mikaPageVo.setTotal(voPage.getTotal());

        return Result.ok("分页成功", mikaPageVo);
    }
}

